package com.moonee.clcomment.controller;

import com.moonee.Entity.Comment;
import com.moonee.Entity.User;
import com.moonee.clapi.commentInterface.CommentInfoInterface;
import com.moonee.clcomment.feign.UserApi;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class CommetInfoController implements CommentInfoInterface {
    
    @Value("${chengliang.name}")
    private String name;
    
    @Autowired
    private UserApi userApi;
    
    @RequestMapping("/getCommentByUser")
    public Comment getCommentByUser(String name) {
        Comment comment = new Comment();
        comment.setContent("真的很好看呢");
        User user = userApi.getUserById(name);
        comment.setUser(user);
        return comment;
    }

    @RequestMapping("/getCommentTimeOut")
    public Comment getCommentTimeOut(String name) {
        System.out.println(Thread.currentThread().getName()+"------------普通方法");
        Comment comment = new Comment();
        comment.setContent("延迟2秒后返回的响应");
        User user = userApi.getUserByTimeOut("chengliang");
        comment.setUser(user);
        System.out.println("评论系统------------"+comment.toString());
        return comment;
    }

    @HystrixCommand(fallbackMethod = "getByHystrixFallBack")
    @RequestMapping("/getByHystrix")
    public Comment getByHystrix(String name) {
        System.out.println(Thread.currentThread().getName()+"------------hystrix方法线程池");
        Comment comment = new Comment();
        comment.setContent("hystrix测试");
        User user = userApi.getUserByTimeOut(name);
        comment.setUser(user);
        return comment;
    }
    
    @RequestMapping("/getByHystrixFallBack")
    public Comment getByHystrixFallBack(String name){
        System.out.println(Thread.currentThread().getName()+"---------fallback线程池s");
        Comment comment = new Comment();
        comment.setContent("hystrix-----fallback");
        return comment;
    }
    
    @RequestMapping("/getConfig")
    public String getConfig(){
        return name;
    }


    /*版本一*/
    /*版本二*/
    /*版本三三三本地冲突*/
    /*版本四*/
    /*版本五*/
    /*版本六*/
    /*版本7冲突*/
}
